package com.eudon.design_pattern.behavioral.mediator;

/**
 * @author eudon
 * @description 中介者模式使用示例
 * @date 2025/9/3
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class Use {
    public static void main(String[] args) {
        // 创建聊天室中介者
        ChatRoom chatRoom = new ChatRoom();
        
        // 创建用户
        User alice = new ConcreteUser("Alice", chatRoom);
        User bob = new ConcreteUser("Bob", chatRoom);
        User charlie = new ConcreteUser("Charlie", chatRoom);
        
        // 将用户添加到聊天室
        chatRoom.addUser(alice);
        chatRoom.addUser(bob);
        chatRoom.addUser(charlie);
        
        System.out.println("\n========== 聊天开始 ==========");
        
        // 用户发送消息
        alice.sendMessage("大家好！我是Alice");
        
        System.out.println();
        
        bob.sendMessage("你好Alice，我是Bob");
        
        System.out.println();
        
        charlie.sendMessage("大家好，很高兴认识你们！");
        
        System.out.println();
        
        alice.sendMessage("今天天气真不错呢~");
        
        System.out.println("\n聊天室当前用户数: " + chatRoom.getUserCount());
    }
}